/*
*   @Author: 1296
*   @Date: 2025-03-20
*   @Description: 语言设置
*/

<template>
  <div class="language-setting">
    <h2>{{ t('title') }}</h2>
    <div class="setting-card">
      <div class="form-group">
        <label for="language-select">👇{{ t('select_language') }}</label>
        <div class="select-wrapper">
          <select id="language-select" v-model="currentLocale">
            <option v-for="lang in languages" :value="lang.value" :key="lang.value">
              {{ lang.label[currentLocale] }}
            </option>
          </select>
          <div class="select-arrow"></div>
        </div>
      </div>
      <div class="current-language">
        <p>🌐{{ t('current_language') }}<span class="highlight">{{ currentLanguageLabel }}</span></p>
      </div>
    </div>
  </div>
</template>

<style scoped>
.current-language p {
  color: #4a5568;
  font-size: 0.95rem;
  margin: 1.5rem 0 0;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.highlight {
  color: #3498db;
  font-weight: 600;
  background: #f0f8ff;
  padding: 0.3rem 0.8rem;
  border-radius: 4px;
  border: 1px solid #e0effe;
}

.language-setting {
  max-width: 480px;
  margin: 2rem auto;
  padding: 0 1rem;
}

h2 {
  color: #2c3e50;
  font-size: 1.6rem;
  text-align: center;
  margin-bottom: 2rem;
  padding-bottom: 0.5rem;
  border-bottom: 3px solid #3498db;
  display: inline-block;
}

.setting-card {
  background: white;
  border-radius: 12px;
  padding: 2rem;
  box-shadow: 0 4px 6px rgba(50, 50, 93, 0.11), 0 1px 3px rgba(0, 0, 0, 0.08);
}

.form-group {
  margin-bottom: 1.5rem;
}

label {
  display: block;
  color: #4a5568;
  font-weight: 500;
  margin-bottom: 0.75rem;
  font-size: 0.9rem;
}

.select-wrapper {
  position: relative;
}

select {
  width: 100%;
  padding: 0.8rem 1.2rem;
  font-size: 1rem;
  border: 2px solid #e2e8f0;
  border-radius: 8px;
  background: white;
  appearance: none;
  transition: border-color 0.3s ease;
  color: #2d3748;
}

select:focus {
  outline: none;
  border-color: #3498db;
  box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

.select-arrow {
  position: absolute;
  right: 1rem;
  top: 50%;
  transform: translateY(-50%);
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 6px solid #718096;
  pointer-events: none;
}

.current-language {
  text-align: center;
  margin-top: 1.5rem;
}

.badge {
  display: inline-block;
  background: #3498db;
  color: white;
  padding: 0.5rem 1rem;
  border-radius: 20px;
  font-size: 0.9rem;
  font-weight: 500;
}

/* 悬停效果 */
select:hover {
  border-color: #cbd5e0;
}

/* 过渡动画 */
.setting-card {
  transition: transform 0.2s ease;
}

.setting-card:hover {
  transform: translateY(-2px);
}
</style>


<script setup>
import { computed } from 'vue'
import { useI18n } from 'vue-i18n'

const { t, locale } = useI18n()

const languages = [
  {
    value: 'zh-CN',
    label: {
      'zh-CN': '简体中文',
      'zh-TW': '簡體中文',
      'en-US': 'Chinese',
      'ja': '簡体字中国語',
      'ko': '중국어 간체'
    }
  },
  {
    value: 'zh-TW',
    label: {
      'zh-CN': '繁体中文',
      'zh-TW': '繁體中文',
      'en-US': 'Traditional Chinese',
      'ja': '繁体字中国語',
      'ko': '중국어 번체'
    }
  },
  {
    value: 'en-US',
    label: {
      'zh-CN': '英语',
      'zh-TW': '英文',
      'en-US': 'English',
      'ja': '英語',
      'ko': '영어'
    }
  },
  {
    value: 'ja',
    label: {
      'zh-CN': '日语',
      'zh-TW': '日文',
      'en-US': 'Japanese',
      'ja': '日本語',
      'ko': '일본어'
    }
  },
  {
    value: 'ko',
    label: {
      'zh-CN': '韩语',
      'zh-TW': '韓文',
      'en-US': 'Korean',
      'ja': '韓国語',
      'ko': '한국어'
    }
  }
];

const currentLocale = computed({
  get: () => locale.value,
  set: (value) => {
    locale.value = value
    sessionStorage.setItem('locale', value)
  }
})

const currentLanguageLabel = computed(() => {
  const found = languages.find(lang => lang.value === locale.value)
  return found ? found.label[locale.value] : ''
})
</script>
